{% extends "base.html" %}

{% block title %}Manage Registrations - {{ activity.title }} - Volunteer Platform{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <h2 class="card-title mb-0">{{ activity.title }} - Registration Management</h2>
                        <a href="{{ url_for('activity_detail', activity_id=activity.id) }}" 
                           class="btn btn-outline-secondary">
                            Back to Activity Details
                        </a>
                    </div>
                    
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle"></i> 
                        Current Registrations: {{ activity.current_participants }}/{{ activity.max_participants }}
                    </div>
                    
                    {% if registrations %}
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Volunteer</th>
                                    <th>Contact Information</th>
                                    <th>Registration Time</th>
                                    <th>Status</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for reg in registrations %}
                                <tr>
                                    <td>{{ reg.volunteer_name }}</td>
                                    <td>
                                        <i class="fas fa-phone"></i> {{ reg.volunteer_phone }}<br>
                                        <i class="fas fa-envelope"></i> {{ reg.volunteer_email }}
                                    </td>
                                    <td>{{ reg.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                                    <td>
                                        {% if reg.status == 'pending' %}
                                            <span class="badge bg-warning">Pending Review</span>
                                        {% elif reg.status == 'approved' %}
                                            <span class="badge bg-success">Approved</span>
                                        {% elif reg.status == 'rejected' %}
                                            <span class="badge bg-danger">Rejected</span>
                                            {% if reg.reject_reason %}
                                            <br><small class="text-muted">{{ reg.reject_reason }}</small>
                                            {% endif %}
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if reg.status == 'pending' %}
                                        <div class="btn-group">
                                            <form method="POST" action="{{ url_for('organization_approve_registration', registration_id=reg.id) }}" class="d-inline">
                                                <button type="submit" class="btn btn-sm btn-success">Approve</button>
                                            </form>
                                            <button type="button" class="btn btn-sm btn-danger" 
                                                    data-bs-toggle="modal" 
                                                    data-bs-target="#rejectModal{{ reg.id }}">
                                                Reject
                                            </button>
                                        </div>
                                        
                                        <!-- Reject Modal -->
                                        <div class="modal fade" id="rejectModal{{ reg.id }}" tabindex="-1">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h5 class="modal-title">Reject Registration</h5>
                                                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                                    </div>
                                                    <form method="POST" action="{{ url_for('organization_reject_registration', registration_id=reg.id) }}">
                                                        <div class="modal-body">
                                                            <div class="mb-3">
                                                                <label for="reject_reason" class="form-label">Reason for Rejection</label>
                                                                <textarea class="form-control" id="reject_reason" 
                                                                          name="reject_reason" rows="3" required></textarea>
                                                            </div>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                                                            <button type="submit" class="btn btn-danger">Confirm Rejection</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <div class="alert alert-info">
                        No registrations yet.
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 